﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Libero.FusionCharts;
using System.Data;

namespace WebApplication1
{
    public partial class exemplo_MS_datasource : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MSBar2DChart oChart = new MSBar2DChart();

            // Set properties
            oChart.Background.BgColor = "ffffff";
            oChart.Background.BgAlpha = 50;
            oChart.ChartTitles.Caption = "# Mobile in last months";

            // Set a template
            oChart.Template = new Libero.FusionCharts.Template.OfficeLightTemplate();

            // Set data   *DataTable OR IList<T>
            DataTable dtSample = GetSalesDataTable();
            oChart.DataSource = dtSample;
            oChart.DataCategoryTextField = "Month";
            oChart.DataSeriesTextField = "Brand";
            oChart.DataSeriesValueField = "Quantity";


            // Link the WebControl and the Chart
            chtProductSales.ShowChart(oChart);
        }

        private DataTable GetSalesDataTable()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Brand", typeof(String));
            dt.Columns.Add("Month", typeof(String));
            dt.Columns.Add("Quantity", typeof(int));

            dt.Rows.Add("Sansung", "08/2010", 2000);
            dt.Rows.Add("Nokia", "08/2010", 3000);
            dt.Rows.Add("Sansung", "09/2010", 1300);
            dt.Rows.Add("Nokia", "09/2010", 2100);
            dt.Rows.Add("Sansung", "10/2010", 3000);
            dt.Rows.Add("Nokia", "10/2010", 3400);
            dt.Rows.Add("Sansung", "11/2010", 5200);
            dt.Rows.Add("Nokia", "11/2010", 7200);

            return dt;
        }
    }
}